/**
 * f-club.cn
 * Copyright (c) 2009-2012 All Rights Reserved.
 */
package com.mtoolkit.socket;

import java.util.concurrent.TimeUnit;

import com.mtoolkit.socket.SocketRequest;
import com.mtoolkit.socket.SocketResponse;
import com.mtoolkit.socket.client.SocketClient;

/**
 * 
 * @author michael
 * @version $Id: Client.java 79 2012-11-05 12:58:10Z xishizhang@gmail.com $
 */
public class Client {
    
    public static void main(String[] args) throws Exception {
        
        SocketRequest request = new SocketRequest("time-request-id");
        request.setRequestData("TIME");
        
        SocketClient client = new SocketClient("localhost", 8611);
        
        int i = 0;
        while (i++ < 3) {
            client.send(request);
            
            SocketResponse response = client.receive(2L, TimeUnit.SECONDS);
            System.out.println("response for request : " + response.getRequestId());
            System.out.println("response data content: " + response.getResponseData());
            
            TimeUnit.SECONDS.sleep(2L);
        }
        
        client.close();
    }
    
}
